package logic

import (
	"context"
	"jingdong_product/models/mysql"

	"jingdong_product/productrpc/internal/svc"
	"jingdong_product/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductUpdateLogic {
	return &ProductUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductUpdateLogic) ProductUpdate(in *productrpc.ProductUpdateRequest) (*productrpc.ProductUpdateResponse, error) {
	// todo: add your logic here and delete this line
	product := mysql.Product{
		Title:        in.Title,
		Content:      in.Content,
		ProductImage: in.ProductImage,
		UserId:       int(in.UserId),
	}
	mysql.DB.Create(&product)
	return &productrpc.ProductUpdateResponse{
		ProductId: int64(product.ID),
	}, nil
}
